const app = getApp()
Page({
    data:{
        oldPass:'',
        pass1:'',
        pass2:''
    },
    oldPass(e){
        this.setData({oldPass:e.detail.value})
    },
    pass1(e){
        this.setData({pass1:e.detail.value})
    },
    pass2(e){
        this.setData({pass2:e.detail.value})
    },
    changePass(){
        if(!this.data.oldPass || !this.data.pass1 || !this.data.pass2){
            wx.showToast({
                title: '请完善信息',
                icon: 'none',
                duration: 1500,
                mask: false
            })
            return
        }
        if(this.data.pass1 != this.data.pass2){
            wx.showToast({
                title: '两次密码不相同,请重新输入',
                icon: 'none',
                duration: 1500,
                mask: false
            })
            return
        }
        let datas = {
            oldPass:this.data.oldPass,
            newPass:this.data.pass1,
            account_id:wx.getStorageSync('phone')
        }
        app.api.post('changePass',datas,(res)=>{
            if(res.data.status == 422){
                wx.showToast({
                    title: '原密码错误',
                    icon: 'none',
                    duration: 1500
                })
            }else if(res.data.status == 200){
               wx.showModal({
                   title: '修改成功',
                   showCancel: false,
                   confirmText: '确定',
                   confirmColor: '#3CC51F',
                   success: (result) => {
                    if(result.confirm){
                       wx.navigateBack({
                        delta: 1
                        })
                    }
                   }
               });
            }
        })
    }
})